/*
  (C) 2007 - Boston University
  Contact: Michael Ocean 

	this file was adapted from a CS511 submission

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench 

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package stepide;

import java.awt.Color;

import javax.swing.JLabel;

/**
 * Overview: This class constructs a status bar, and allows messages to be set. The
 * ability to set messages with a color is provided to supply additional
 * feedback to the user about the status of the application. Any setting of the
 * message should include one of the MSG constants defined here.
 * 
 */
public class StatusBar extends JLabel {
	/** sets a black message */
	public static final int MSG_DEFAULT = 1;
	/** sets a red message */
	public static final int MSG_ERROR = 2;
	/** sets a green message */
	public static final int MSG_OK = 3;
	/** sets an orange message */
	public static final int MSG_WARNING = 4;
	
	private static final Color DARK_GREEN = new Color(Color.GREEN.getRed(), Color.GREEN.getGreen(), Color.GREEN.getBlue()).darker().darker();
	private static final Color DARK_RED = new Color(Color.RED.getRed(), Color.RED.getGreen(), Color.RED.getBlue()).darker();
	private static final Color DARK_ORANGE = new Color(Color.ORANGE.getRed(), Color.ORANGE.getGreen(), Color.ORANGE.getBlue()).darker();
	private static final long serialVersionUID = 20070428;
	public static final String DEFAULT_MSG_NODES = "Node Mode: Double-click the canvas to add nodes";
	public static final String DEFAULT_MSG_ARROW_BEGIN = "Connector Mode: Click the parent node";
	public static final String DEFAULT_MSG_ARROW_END = "Connector Mode: Click the child node";
	private static String DEFAULT_MSG = null;
	
	public StatusBar() {
		super();
		// super.setPreferredSize(new Dimension(100, 16));
		//setMessage("Ready to add nodes", MSG_OK);
		setDefaultMessage();
	}

	/**
	 * Sets the status bar message with a color
	 * 
	 * @param message
	 *            the text to set
	 * @param type
	 *            one of the MSG constants defined in this class
	 */
	public void setMessage(String message, int type) {
		switch (type) {
			case MSG_DEFAULT:
				super.setForeground(Color.BLACK);
				break;
			case MSG_ERROR:
				super.setForeground(DARK_RED);
				break;
			case MSG_OK:
				super.setForeground(DARK_GREEN);
				break;
			case MSG_WARNING:
				super.setForeground(DARK_ORANGE);
				break;
		}
		super.setText(" " + message);
		super.repaint();
	}

	/** Sets the default message */
	public void setDefaultMessage() {
		setMessage(DEFAULT_MSG, MSG_OK);
	}
	
	public void alterDefaultMessage(String msg){
		DEFAULT_MSG = msg;
		setDefaultMessage();
	}
	/**
	 * Sets the status bar message with a color for a specified duration
	 * 
	 * @param message
	 *            the text to set
	 * @param type
	 *            one of the MSG constants defined in this class *param
	 *            msDuration time to display the message in milliseconds
	 */
	public void setMessageWithTimer(String msg, int type, long msDuration) {
		setMessage(msg, type);

		// TODO
	}
}